/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-24
 * Time: 22:46
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;

using tools;

using Labb4.Pooman.Game;

namespace Labb4.Main
{
	/// <summary>
	/// A window that lets the player set some settings.
	/// 
	/// Available settings are:
	/// Debug mode (will display some information about the graphics)
	/// Ai play with open cards (lets the player see the computer's cards)
	/// Mute audio
	/// Display tool tips
	/// The display time for the cards, how long they will stay on screen after a stick is finished
	/// </summary>
	public partial class SettingsForm
	{
		#region members
		
		/// <summary>
		/// Reference to the Properties singleton
		/// </summary>
		private Properties		m_Settings = Properties.Instance;
		
		#endregion
		
		#region constructor
		
		/// <summary>
		/// Constructor, initializes the window, and sets the checkboxes and textfield
		/// </summary>
		public SettingsForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			CheckDebug.Checked = m_Settings.Debug;
			CheckOpenCards.Checked = m_Settings.OpenCards;
			CheckMute.Checked = m_Settings.MuteAudio;
			CheckTooltip.Checked = m_Settings.ToolTip;
			DisplayTimeTextBox.Text = m_Settings.DisplayTimeForWonCards.ToString();
		}
		
		#endregion
		
		#region callbacks
		
		/// <summary>
		/// Handles events triggered by left clicking the OK or Cancel buttons.
		/// If the OK button was pressed, the Properties singleton class is updated
		/// with the information found in the window. This information is also
		/// stored in the settings file, so that the settings are remembered the
		/// next time the program is started.
		/// </summary>
		/// <param name="sender">Reference to the button that fired the event</param>
		/// <param name="e">?</param>
		protected void Buttons(object sender, System.EventArgs e)
		{
			if(sender == FormOK)
			{
				m_Settings.Debug = CheckDebug.Checked;
				m_Settings.OpenCards = CheckOpenCards.Checked;
				m_Settings.MuteAudio = CheckMute.Checked;
				m_Settings.ToolTip = CheckTooltip.Checked;
				
				if(!DisplayTimeTextBox.Text.Equals(""))
				{
					try
					{
						int displayTime = int.Parse(DisplayTimeTextBox.Text);
						m_Settings.DisplayTimeForWonCards = displayTime;
					}
					catch
					{
					}
				}
				
				List<string> fileContent = new List<string>();
				fileContent.Add("debug " + m_Settings.Debug.ToString().ToLower());
				fileContent.Add("open_cards " + m_Settings.OpenCards.ToString().ToLower());
				fileContent.Add("mute_audio " + m_Settings.MuteAudio.ToString().ToLower());
				fileContent.Add("help_bubbles " + m_Settings.ToolTip.ToString().ToLower());
				fileContent.Add("display_time " + m_Settings.DisplayTimeForWonCards.ToString());
				
				ListFileTool file = new ListFileTool();
				file.SaveListToFile(m_Settings.StartPath + "resources\\configfiles\\settings.txt", fileContent, true);
			}
			
			this.Close();
		}
		
		#endregion
	}
}
